home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: char* to char array[] ?
- Date: 13 Jan 1996 00:18:59 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4d7fc3$i5g@umbc9.umbc.edu>
- References: <4d4n9s$9uv@ixnews2.ix.netcom.com> <1996Jan13.013852.19365@hns.com>
- NNTP-Posting-Host: f-umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Ralph Sweitzer <t_rsweitzer> wrote:
- |> Try something like this it should work.
- |>
- |> /* prototype */
- |> char *called_finction(void);
-
- That needs to be "char *called_function (void);". One point off for
- spelling ;-).
-
- |> void calling_function(void)
- |> {
- |> char *ptr;
- |> ptr = called_function();
- |> }
- |>
- |> char *called_function(void)
- |> {
- |> char buf[] = {"hello world"};
- |> return((char *)buf);
- |> }
-
- Obviously you are trying to help whomever the original poster was, but
- advice like this will do more harm than good. See, C is a pass by value
- language except where arrays and function names decay to pointers. You
- are returning a local array which is no longer valid once the function
- called_function() exits and whatever value calling_function() receives
- is totally undefined.
-
- See FAQ question 7.5...I won't post it so you'll have to actually
- read it yourself.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-